* Construct final goods import shares at the country level from OECD
clear
set more off
local countries "AUS AUT BEL CAN CHL CZE DNK EST FIN FRA DEU GRC HUN ISL IRL ISR ITA JPN LUX NLD NZL NOR POL PRT SVK SVN ESP SWE CHE GBR USA BGR BRN CHN CRI CYP HKG HRV IND KHM LTU LVA MLT PHL ROU SAU SGP TUN TWN VNM ZAF RoW BRA RUS IDN KOR TUR MYS ARG COL MEX THA"
foreach cc of local countries {
foreach t of numlist 1995(1)2011 {
import delimited using "OECD/input/`cc'`t'domimp", clear
keep v1 cons 
gen var = _n
drop if var>68
gen dom = 0
replace dom =1 if var<=34
gen imp = 0
replace imp =1 if var>=35
egen totalpurch = total(cons)
gen cons_dom = cons * dom
gen cons_imp = cons * imp
egen totalDOM = total(cons_dom)
egen totalIMP = total(cons_imp)
gen importshare = totalIMP / totalpurch
keep if var==1
keep importshare
gen year=`t'
gen Country="`cc'"
save "OECD/temp/`cc'`t'.dta", replace
}
use "OECD/temp/`cc'1995.dta"
foreach t of numlist 1996(1)2011 {
append using "OECD/temp/`cc'`t'.dta"
}
save "OECD/temp/`cc'_append.dta", replace
}
local countries2 "AUS AUT BEL CAN CHL CZE DNK EST FIN FRA DEU GRC HUN ISL IRL ISR ITA JPN LUX NLD NZL NOR POL PRT SVK SVN ESP SWE CHE GBR USA BGR BRN CHN CRI CYP HKG HRV IND KHM LTU LVA MLT PHL ROU SAU SGP TUN TWN VNM ZAF RoW BRA RUS IDN KOR TUR MYS ARG COL MEX"
foreach cc of local countries2 {
append using "OECD/temp/`cc'_append.dta"
}
save "OECD/output/IMPORTSHARES_OECD_Consumption.dta", replace

